/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cpal.entrenamiento.common.logger;

/**
 *
 * @author omar
 */
public class LogFactory {

    private static LogFactory factory = null;
    private Log logger = null;

    private LogFactory() {
    }

    /**
     * Convenience method to derive a name from the specified class and
     * call <code>getInstance(String)</code> with it.
     *
     * @param clazz Class for which a suitable Log name will be derived
     */
    public Log getInstance(Class clazz) {

        return (getInstance(clazz.getName()));

    }

    /**
     * <p>Construct (if necessary) and return a <code>Log</code> instance,
     * using the factory's current set of configuration attributes.</p>
     *
     * <p><strong>NOTE</strong> - Depending upon the implementation of
     * the <code>LogFactory</code> you are using, the <code>Log</code>
     * instance you are returned may or may not be local to the current
     * application, and may or may not be returned again on a subsequent
     * call with the same name argument.</p>
     *
     * @param name Logical name of the <code>Log</code> instance to be
     *  returned (the meaning of this name is only known to the underlying
     *  logging implementation that is being wrapped)
     */
    public Log getInstance(String name) {

        try {
            if (logger == null) {
                logger = new Log4jLogger();
            }
        } catch (Exception exc) {
        }
        return logger;
    }

    /**
     * <p>Construct (if necessary) and return a <code>LogFactory</code>
     * instance, using the following ordered lookup procedure to determine
     * the name of the implementation class to be loaded.</p>
     */
    public static LogFactory getFactory() {
        if (factory == null) {
            factory = new LogFactory();
        }
        return factory;
    }

    /**
     * Convenience method to return a named logger, without the application
     * having to care about factories.
     *
     * @param clazz Class from which a log name will be derived
     */
    public static Log getLog(Class clazz) {

        return (getFactory().getInstance(clazz));

    }

    /**
     * Convenience method to return a named logger, without the application
     * having to care about factories.
     *
     * @param name Logical name of the <code>Log</code> instance to be
     *  returned (the meaning of this name is only known to the underlying
     *  logging implementation that is being wrapped)
     */
    public static Log getLog(String name) {

        return (getFactory().getInstance(name));

    }
}
